import {createRouter,createWebHistory} from 'vue-router'
import store from '@/store'

const routes = [
    {
        path:'/test',
        component:()=>import('../views/Home.vue')
    },
    {
        path:'/login',
        component:()=>import('../views/Login.vue')
    },
    {
        path: '/',
        redirect: '/first'
    },
    {
        path: '/home',
        component:()=>import('../components/Home.vue'),
        children: [
            {
                path:'/first',
                component:()=>import('../components/First.vue')
            },
            {
                path:'/message',
                component:()=>import('../components/Message.vue')
            },
        
            {
                path:'/:pathMatch(.*)*',
                name:'NotFound',
                component:()=>import('../views/404.vue')
            }
        ]
    },
    
]

const router = createRouter({
    history:createWebHistory(),
    routes
})

router.beforeEach(async (to, from, next) => {
    const res = await store.dispatch('getUserInfo')
    next()
})

export default router